#!/bin/bash

# 检查kamailio进程是否存在
if pgrep kamailio > /dev/null; then
    echo "Kamailio process found. Killing the process..."
    # 如果存在，则杀死进程
    pkill -9 kamailio

    # 等待进程终止
    sleep 5
    echo "Kamailio process killed."
fi

# 进入执行目录
cd /usr/local/etc/kamailio

# 设置config变量
if [ -n "$1" ]; then
    config="$1"
    echo "Config parameter provided: $config"
else
    config="kamailio.cfg"
    echo "No config parameter provided. Using default config: $config"
fi

# 重启kamailio
echo "Restarting Kamailio..."
kamailio -E -f "$config" 
echo "Kamailio restarted."

